package com.changgou.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.InetSocketAddress;

/**
 * @program: changgou_parent
 * @author: zhanzhewan
 * @create: 2020-03-23 12:32
 **/
@Component
public class IpFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        ServerHttpRequest request = exchange.getRequest();
        InetSocketAddress remoteAddress = request.getRemoteAddress();
        System.out.println("ip======{}"+remoteAddress);
        System.out.println("hello world");
        return chain.filter(exchange);
    }


    /**
     * @Description: 网关中如果有多个这样的过滤器 按这里的数字来依次过滤
     * @Param:
     * @return:
     */
    @Override
    public int getOrder() {
        return 1;
    }
}
